package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @version 1.0
 * @Author 杨旭康
 * @Date 2023/2/6 19:23
 * @question:
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 用户登录
     *
     * @param userInfo
     * @return
     */
    @Override
    public UserInfo loginR(UserInfo userInfo) {

        String loginName = userInfo.getLoginName();
        String passwd = userInfo.getPasswd();
        //密码进行MD5加密
        String newPasswd = DigestUtils.md5DigestAsHex(passwd.getBytes());

        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("login_name", loginName);
        wrapper.eq("passwd", newPasswd);
        UserInfo user = userInfoMapper.selectOne(wrapper);

        if (user != null) {

            return user;
        }
        return null;
    }







}




